<html>
<head><meta charset="utf-8"><title>Attaching diagnostics to tokens · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attaching.20diagnostics.20to.20tokens.html">Attaching diagnostics to tokens</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218087566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attaching%20diagnostics%20to%20tokens/near/218087566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attaching.20diagnostics.20to.20tokens.html#218087566">(Nov 27 2020 at 12:43)</a>:</h4>
<p>I'd like to attach a diagnostic to a specific token in an attribute. This token is not its own syntax node, since it's just part of the attributes <code>TokenTree</code>.</p>
<p>Is there any existing way to accomplish this? I don't see any, since diagnostics are always attached to <code>SyntaxNodePtr</code>s, which only work for nodes, not <code>SyntaxElement</code>s.</p>



<a name="218088278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attaching%20diagnostics%20to%20tokens/near/218088278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attaching.20diagnostics.20to.20tokens.html#218088278">(Nov 27 2020 at 12:51)</a>:</h4>
<p>on the IDE level the diagnostic just has a TextRange, so it should be possible to narrow the range during diagnostic collection there. You could use the token ID of the token in the tree in the HIR diagnostic, I guess?</p>



<a name="218088701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attaching%20diagnostics%20to%20tokens/near/218088701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attaching.20diagnostics.20to.20tokens.html#218088701">(Nov 27 2020 at 12:55)</a>:</h4>
<p>hmm, yeah, that's right</p>



<a name="218167975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Attaching%20diagnostics%20to%20tokens/near/218167975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Attaching.20diagnostics.20to.20tokens.html#218167975">(Nov 28 2020 at 15:07)</a>:</h4>
<p>Yeah, the idea is that diagnostic struct are more semantic-based, and that rendering them into specific ranges is handled by an IDE. It might make sense to document that somewhere though.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>